<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>定义一个常量</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.constant.html">constant</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.defined.html">defined</a></div>
 <div class="up"><a href="ref.misc.html">杂项 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.define" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">define</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">define</span> &mdash; <span class="dc-title">定义一个常量</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.define-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>define</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$case_insensitive</code><span class="initializer"> = false</span></span>
  ] )</div>

  <p class="para rdfs-comment">
  在运行时定义一个常量。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.define-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">name</code></em></dt>

     <dd>

      <p class="para">
       常量名。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">value</code></em></dt>

     <dd>

      <p class="para">
      常量的值；仅允许标量和 <span class="type"><a href="language.types.null.html" class="type null">null</a></span>。标量的类型是 <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>，
       <span class="type"><a href="language.types.float.html" class="type float">float</a></span>，<span class="type"><a href="language.types.string.html" class="type string">string</a></span> 或者 <span class="type"><a href="language.types.boolean.html" class="type boolean">boolean</a></span>。
       也能够定义常量值的类型为 <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> ，但并不推荐这么做，可能会导致未知状况的发生。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">case_insensitive</code></em></dt>

     <dd>

      <p class="para">
       如果设置为 <strong><code>TRUE</code></strong>，该常量则大小写不敏感。默认是大小写敏感的。比如，
       <em>CONSTANT</em> 和 <em>Constant</em> 代表了不同的值。
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        大小写不敏感的常量以小写的方式储存。
       </p>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.define-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.define-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3679">
    <p><strong>Example #1 定义常量</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />define</span><span style="color: #007700">(</span><span style="color: #DD0000">"CONSTANT"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;world."</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">CONSTANT</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;outputs&nbsp;"Hello&nbsp;world."<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">Constant</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;outputs&nbsp;"Constant"&nbsp;and&nbsp;issues&nbsp;a&nbsp;notice.<br /><br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"GREETING"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;you."</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">GREETING</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;outputs&nbsp;"Hello&nbsp;you."<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">Greeting</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;outputs&nbsp;"Hello&nbsp;you."<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.define-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.defined.html" class="function" rel="rdfs-seeAlso">defined()</a> - 检查某个名称的常量是否存在</span></li>
    <li class="member"><span class="function"><a href="function.constant.html" class="function" rel="rdfs-seeAlso">constant()</a> - 返回一个常量的值</span></li>
    <li class="member"><a href="language.constants.html" class="link">Constants</a>这一节</li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.constant.html">constant</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.defined.html">defined</a></div>
 <div class="up"><a href="ref.misc.html">杂项 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
